//
//  SEGLouDongListViewModel.m
//  SEGViewModel
//
//  Created by 山刘 on 2020/6/5.
//

#import "SEGLouDongListViewModel.h"


@implementation SEGLouDongListViewModel
#pragma mark - Init
-(instancetype)init{
    if (self = [super init]) {
        [self racInit];
    }
    return self;
}
- (void)racInit {
    @weakify(self);
    _requestDataCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self)
            //请求查询项目下辖楼栋列表
            [self.myProfileManager requestBuildingListBycommunityId:kAccountCommunityID Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                if (!isSuccessed) {
                    [self.messageDataSubject sendNext:errorMessage];
                }
                [subscriber sendNext:nil];
                [subscriber sendCompleted];
            }];
            
            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
    
    _unitDataCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(NSString *  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self)
            // 请求单元列表
            [self.myProfileManager requestQueryHouseByUnitBuildingID:input Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                if (!isSuccessed) {
                    [self.messageDataSubject sendNext:errorMessage];
                }
                [subscriber sendNext:nil];
                [subscriber sendCompleted];
            }];
            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
}

#pragma mark - Publish Methods

#pragma mark - Private Methods

#pragma mark - Getter
- (SEGMyProfileManager *)myProfileManager {
    if (!_myProfileManager) _myProfileManager = [[SEGMyProfileManager alloc] init];
    return _myProfileManager;
}

-(RACSubject *)messageDataSubject{
    if (!_messageDataSubject) {
        _messageDataSubject = [RACSubject subject];
    }
    return _messageDataSubject;
}
#pragma mark - Stter
@end
